package com.radar.io.radar346.DataType;

import cn.hutool.core.io.FastByteArrayOutputStream;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ZipUtil;
import com.radar.exception.RadarDecodeError;
import com.radar.utils.BitConverter;
import org.python.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class Test {
    private static final int SIZE_OF_INT = 4;
    private static final int SIZE_OF_SHORT = 2;
    private static final ByteOrder ORDER = ByteOrder.nativeOrder();

    public static void main(String[] args) throws IOException, RadarDecodeError {

        int m = 1 ;
        System.out.println(Integer.toUnsignedLong(m));


        byte[] bytes = FileUtil.readBytes("D:\\work\\guorong\\国天资料\\激光测风雷达\\20220322\\HMPWL20220322134827_001_AVG2_TR120_DIS30_风廓线测量.WPD");
        byte[] bytes1 = decompressBZ2(bytes);
        int index = 208 ;

        int i1 = BitConverter.toInt16(bytes1, index);  //秒
        index +=2 ;
        int i2 = BitConverter.toInt16(bytes1, index); //分
        index +=2 ;
        int i3 = BitConverter.toInt16(bytes1, index);  //时
        index +=2 ;
        int i4 = BitConverter.toInt16(bytes1, index);  //日
        index +=2 ;
        int i5 = BitConverter.toInt16(bytes1, index); //月
        index +=2 ;
        int i6 = BitConverter.toInt16(bytes1, index); //年
        index +=2 ;
        int i7 = BitConverter.toInt16(bytes1, index);
        index +=2 ;

    }


    public static byte[] decompressBZ2(byte[] bytes) throws RadarDecodeError {
        try (ByteArrayInputStream fis = new ByteArrayInputStream(bytes);
             BZip2CompressorInputStream bis = new BZip2CompressorInputStream(fis);
             FastByteArrayOutputStream fastByteArrayOutputStream = new FastByteArrayOutputStream(bytes.length)) {
            int count;
            byte data[] = new byte[2048];
            while ((count = bis.read(data)) != -1) {
                fastByteArrayOutputStream.write(data, 0, count);
            }
            fastByteArrayOutputStream.flush();
            return fastByteArrayOutputStream.toByteArray();
        } catch (Exception e) {
            throw new RadarDecodeError("decompressBZ2 failed");
        }
    }


    public static byte[]  getXx(byte[] bytes, int read, int start){
        // 分离时间字段
        byte[] readByte = new byte[read];
        System.arraycopy(bytes, start, readByte, 0, read);
        return  readByte ;
    }



}
